package initialize

import (
	"errors"
	"jtvss/configs"
	"jtvss/pkg/orm"

	"github.com/glebarez/sqlite"
)

type Options struct {
	Name    string `json:"name"`
	Address string `json:"address"`
}

func Database() error {
	var o Options
	if err := configs.GViper.UnmarshalKey("sql", &o); err != nil {
		return err
	}
	switch o.Name {
	case "sqlite":
		return orm.CreateDB(sqlite.Open(o.Address), false)
	}
	return errors.New("invalid database")
}
